package com.ijustyce.market;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.ijustyce.market.GlideImageLoader;
import com.ijustyce.market.ItemAndAdapter.MyAdapter;
import com.ijustyce.market.ItemAndAdapter.goods;
import com.ijustyce.market.R;

import com.youth.banner.Banner;

import java.util.ArrayList;
import java.util.List;

public class My_Fragment extends Fragment {

    private View view;
    private Banner banner;
    private List<goods> goodsList = new ArrayList<>();

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        List images = new ArrayList();
        images.add(R.drawable.material_design_3);
        images.add(R.drawable.material_design_4);
        images.add(R.drawable.material_design_5);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment

        view=inflater.inflate(R.layout.fragment_my, container, false);

        //获取资源id
        banner = view.findViewById(R.id.DE_banner);

        //创建图片地址集合
        List images = new ArrayList();
        images.add(R.drawable.material_design_3);
        images.add(R.drawable.material_design_4);
        images.add(R.drawable.material_design_5);

        banner.setImageLoader(new GlideImageLoader());
        banner.setImages(images);
        banner.start();

        initFruits();
        RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.rv);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
        recyclerView.setLayoutManager(layoutManager);
        MyAdapter adapter = new MyAdapter(goodsList);
        recyclerView.setAdapter(adapter);
        return view;
    }
    private void initFruits() {
        for (int i = 0; i < 100; i++) {
            goods apple = new goods("Apple", R.drawable.game_2048,"64","山东青岛","1254");
            goodsList.add(apple);
            goods banana = new goods("Banana", R.drawable.flutter_demo,"64","山东青岛","1254");
            goodsList.add(banana);
            goods orange = new goods("Orange", R.drawable.all_messenger,"64","山东青岛","1254");
            goodsList.add(orange);
            goods watermelon = new goods("Watermelon", R.drawable.gray_radius,"64","山东青岛","1254");
            goodsList.add(watermelon);


        }
    }

//    private View.OnClickListener Change=new View.OnClickListener() {
//
//        @Override
//        public void onClick(View v) {
//            switch (v.getId()){
//                case R.id.imageButton1:
//                    Intent intent=new Intent(getContext(),IndexPage.class);
//                    startActivity(intent);
//                    break;
//                case R.id.imageButton2:
//                    Intent intent1=new Intent(getContext(),Shop_Fragment_Container.class);
//                    startActivity(intent1);
//                    break;
//                case R.id.imageButton3:
//                    Intent intent2=new Intent(getContext(),BottomNavigationActivity.class);
//                    startActivity(intent2);
//                    break;
//                case R.id.imageButton4:
//                    Intent intent4=new Intent(getContext(),ScrollingActivity.class);
//                    startActivity(intent4);
//                    break;
//            }
//        }
//    };
}